
package com.hlkj.pay.controller.merchant;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import java.util.Collections;
import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.common.pojo.PageResult;
import com.hlkj.framework.common.util.collection.CollectionUtils;
import com.hlkj.pay.app.merchant.IMerchantReportAmountAppService;
import com.hlkj.pay.controller.BaseController;
import com.hlkj.pay.dto.merchant.report.MerchantReportAmountPageDto;
import com.hlkj.pay.dto.merchant.report.MerchantReportAmountPageQueryDto;
import com.hlkj.pay.service.merchant.IMerchantReportAmountService;
import com.hlkj.pay.vo.merchant.req.report.MerchantReportAmountPageReq;
import com.hlkj.pay.vo.merchant.resp.report.MerchantReportAmountListResp;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

/**
 * @author HlpayTeam
 * @date 2024/09/12 11:32
 */
@Tag(name = "汇电通-入金记录管理")
@RestController
@RequestMapping("/v1/merchant/report/amount")
@RequiredArgsConstructor
public class MerchantAmountController extends BaseController {

    private final IMerchantReportAmountService merchantReportAmountService;
    private final IMerchantReportAmountAppService merchantReportAmountAppService;

    @Operation(summary = "汇电通入金列表")
    @GetMapping("")
    CommonResult<PageResult<MerchantReportAmountListResp>> merchantReportAmountPage(MerchantReportAmountPageReq reportAmountPageReq) {
        MerchantReportAmountPageQueryDto merchantReportInfoPageQueryDto = BeanUtil.copyProperties(reportAmountPageReq, MerchantReportAmountPageQueryDto.class);
        processQueryDate(reportAmountPageReq, merchantReportInfoPageQueryDto);
        merchantReportInfoPageQueryDto.setLikeSn(merchantReportInfoPageQueryDto.getSn());
        merchantReportInfoPageQueryDto.setSn(null);
        merchantReportInfoPageQueryDto.setLikeSn(reportAmountPageReq.getSn());
        merchantReportInfoPageQueryDto.setLikeUserId(reportAmountPageReq.getLikeUserId());
        PageResult<MerchantReportAmountPageDto> page = merchantReportAmountService.queryAmountPage(merchantReportInfoPageQueryDto);
        List<MerchantReportAmountPageDto> list = page.getList();
        if (CollectionUtils.isEmpty(list)) {
            return buildPageResult(page, Collections.emptyList());
        }
        List<MerchantReportAmountListResp> merchantReportInfoListResps = BeanUtil.copyToList(list, MerchantReportAmountListResp.class);
        processProvideList(merchantReportInfoListResps);
        return buildPageResult(page, merchantReportInfoListResps);
    }
    @Operation(summary = "汇电通调拨凭证")
    @GetMapping("/allot/proof")
    public CommonResult<String> queryAllotProof(@RequestParam(name = "code", required = false) String code) {
        return merchantReportAmountAppService.queryAllotProof(code, false);
    }
}
